package com.good.webadmin.Utils;

import com.good.webadmin.Models.Audience;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.DigestUtils;

@Slf4j
@Component
public class SignUtil {
    @Autowired
    private Audience audience;
    public boolean check(long timestamp,String sign,String keys){
        long  nowtimestamp=  System.currentTimeMillis();
        //todo 方便测试目前暂定超时时间比较大，后续更改
        if(nowtimestamp-timestamp>3000000)
        {
            return  false;
        }else
        {
            String str=timestamp+audience.getSecretKey()+keys;
            str= DigestUtils.md5DigestAsHex(str.getBytes());
            log.info("appSign:[{}] paramSign[{}]",str,sign);
            return str.equals(sign);
        }

    }
}
